/**
 * 
 */
package nl.sportan.samenloop.communication;

import java.util.ArrayList;

import nl.sportan.samenloop.model.ProgramItem;

/**
 * @author bram
 *
 */
public class ClockReader implements Runnable {

	private String url;
	private Result<Long> resultHandler = null;
	
	public ClockReader(String url) {
		this.url = url;
	}
	
	
	public void setResultHandler(Result<Long> resultHandler) {
		this.resultHandler = resultHandler;
	}
	
	private long readClock() {
		String result = Utils.retrieveData(url);
		long time = 0; 

		if (result != null && result.length() > 0){
			try {
			
			time =  Long.parseLong(result);
			} catch (NumberFormatException nfe) {
				
			}
		}
		
		return time;
	}
	
	
	
	public void run() {
		long time = readClock();
		resultHandler.onSucces(time);
	}

}
